<template>
<h1>员工列表练习</h1>
  <hr>
  <input type="text" v-model="emp.name" placeholder="输入姓名">
  <input type="text" v-model="emp.salary" placeholder="输入工资">
  <input type="text" v-model="emp.job" placeholder="输入岗位">
  <button @click="add">点我添加</button>

  <table border="1px">

    <tr>
      <th>编号</th>
      <th>员工姓名</th>
      <th>员工工资</th>
      <th>员工岗位</th>
    </tr>

    <tr v-for="(item,index) in arr">
      <td>{{index+1}}</td>
      <td>{{item.name}}</td>
      <td>{{item.salary}}</td>
      <td>{{item.job}}</td>

    </tr>
  </table>
</template>
<script setup>

import {ref} from "vue";

const emp=ref({
  name:'',
  salary:'',
  job:''
});
const arr=ref([]);


const add=()=>{
  if (emp.value.name.trim()=='' || emp.value.salary.trim()==''|| emp.value.job.trim()==''){
    alert("请输入信息");
    return;
  }
    arr.value.push(emp.value)
  emp.value={
    name:'',
    salary:'',
    job:''
      };


}

</script>


<style scoped>

</style>